<template>
  <div class="common-layout">
    <el-container>
      <el-header class="header">
        <div class="flex float-left headerLeft">
          <img v-bind:src="logo" alt="" class="logo">
          <div class="line"></div>
          <p class="title ">战略微头条</p>
        </div>
        <div class="flex float-right headerRight">
          <el-button type="primary" @click="handleExitPreview">退出预览</el-button>
        </div>
      </el-header>
    </el-container>
  </div>

  <div class="container">
    <img src="../../assets/phone-head.png" alt="" class="phone-head">
    <div class="flex justify-center items-center">
      <span @click="handlePreviewList" class="margin-left: 0">
        < </span>
          <h1>战略微头条</h1>
    </div>
    <hr />

    <h1 class="cover-container">{{ currentNews && currentNews.newsTitle ? currentNews.newsTitle : '战略微头条' }}</h1>

    <div v-if="currentNews && currentNews.abstractReal" class="abstract-container">
      <p>{{ currentNews.abstractReal }}</p>
    </div>
  </div>
</template>

<script setup>
import logo from '@/assets/logo.png'
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const route = useRoute()

const handlePreviewList = () => {
  router.push({ name: 'preview' })
}

const handleExitPreview = () => {
  router.push({
    name: 'post',
    query: { step: route.query.step } // 携带步骤参数
  });
}

const releaseList = ref([])
const formData = ref(null)
const currentNews = ref(null)

onMounted(() => {
  try {
    const newsListData = sessionStorage.getItem('previewNewsList')
    if (newsListData) {
      releaseList.value = JSON.parse(newsListData)

      const newsId = route.query.id
      if (newsId !== undefined && releaseList.value[newsId]) {
        currentNews.value = releaseList.value[newsId]
        console.log('当前新闻详情：', currentNews.value)
      }
    }
    const formDataStr = sessionStorage.getItem('previewFormData')
    if (formDataStr) {
      formData.value = JSON.parse(formDataStr)
    }
  } catch (error) {
    console.error('获取预览数据失败', error)
  }
})
</script>

<style scoped>
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}

.header {
  height: 6vh;
  padding: 0;
  box-sizing: border-box;
  border-bottom: 1px solid #eee;
}

.headerLeft {
  padding: 1vh 0 0 2vw;
}

.headerRight {
  line-height: 6vh;
  padding-right: 1vw;
}

.container {
  height: 700px;
  max-width: 400px;
  margin: 80px auto;
  border: #000000 10px solid;
  border-radius: 50px;
}

.logo {
  width: 7vw;
  height: 4vh;
}

.line {
  width: 1px;
  height: 1.5vh;
  background-color: #eee;
  margin: 1.4vh 1.5vw 0;
}

.title {
  font-weight: 500;
  line-height: 4vh;
}

.active {
  background-color: #E8F6FE;
  border-color: #3E88CF;
  color: #438BD0
}

.phone-head {
  width: 100%;
}

h1 {
  text-align: center;
  font-size: 28px;
  font-weight: 900;
  font-size: 30px;
}

.newsItem {
  padding: 15px 0;
}

.news-content {
  padding: 0 15px;
}

.news-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 8px 0;
  color: #333;
}

.cover-container {
  margin: 15px 0;
}

.cover-image {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.abstract-container {
  padding: 10px 15px;
  margin: 10px 0;
  background-color: #f9f9f9;
  border-radius: 4px;
}

.abstract-container p {
  margin: 0;
  line-height: 1.6;
  color: #333;
}
</style>